// poj2796
// 题意：给定n(<=100000)个数ai([0, 10^6])，求一端区间使得区间的和
//       乘以区间内最小数的积最大。
//
// 题解：最小值很容易用单调队列维护。那么我们可以考虑对每个值，
//       以它做为最小值从左延伸最远距离，往右最远，最后求个最大值就行。
//       忘了给答案的l，r赋初始值在全为零的时候wa了一次。
//
// 统计：782ms, 15min, 1wa
//
// run: $exec < input
#include <cstdio>

int const inf = 1 << 28;
int const maxn = 100100;
int da[maxn];
long long sum[maxn];
int l[maxn], r[maxn];

int monoq[4 * maxn];
int head, tail;
int n;


int main()
{
	std::scanf("%d", &n);
	for (int i = 1; i <= n; i++) std::scanf("%d", &da[i]);
	da[0] = da[n + 1] = -inf;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + da[i];

	head = 1; tail = 0; monoq[++tail] = 0;
	for (int i = 1; i <= n; i++) {
		while (head <= tail && da[i] <= da[monoq[tail]]) tail--;
		monoq[++tail] = i;
		l[i] = monoq[tail - 1];
	}
	head = 1; tail = 0; monoq[++tail] = n + 1;
	for (int i = n; i >= 1; i--) {
		while (head <= tail && da[i] <= da[monoq[tail]]) tail--;
		monoq[++tail] = i;
		r[i] = monoq[tail - 1] - 1;
	}

	/*
	for (int i = 1; i <= n; i++)
		std::printf("%d %d\n", l[i], r[i]);
	*/

	long long ans = 0, ansl = 1, ansr = 1;
	for (int i = 1; i <= n; i++) {
		long long tl = sum[i] - sum[l[i]];
		long long tr = sum[r[i]] - sum[i];
		tl = (tl + tr) * da[i];
		if (tl > ans) {
			ans = tl;
			ansl = l[i] + 1;
			ansr = r[i];
		}
	}
	std::printf("%lld\n%lld %lld\n", ans, ansl, ansr);
}


